package com.colliery.model;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class test {
    public static void main(String[] args) throws ParseException {

        //System.out.println(transfom(900005));
       // findDates("2021-10-01","2021-11-2");
        getDate("2021-11-02 09:41:27");
    }
    public static String transfom(final int time) {
        int hh = time / 3600;
        int mm = (time % 3600) / 60;
        int ss = (time % 3600) % 60;
        return (hh < 10 ? ("0" + hh) : hh) + ":" + (mm < 10 ? ("0" + mm) : mm) + ":" + (ss < 10 ? ("0" + ss) : ss);
    }

    public static List<String> findDates(String dBegin, String dEnd) throws ParseException, java.text.ParseException {
        //日期工具类准备
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        //设置开始时间
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(format.parse(dBegin));

        //设置结束时间
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(format.parse(dEnd));

        //装返回的日期集合容器
        List<String> Datelist = new ArrayList<String>();
        //将第一个月添加里面去
        Datelist.add(format.format(calBegin.getTime()));
        // 每次循环给calBegin日期加一天，直到calBegin.getTime()时间等于dEnd
        while (format.parse(dEnd).after(calBegin.getTime()))  {
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            Datelist.add(format.format(calBegin.getTime()));
        }

        System.out.println(Datelist);
        return Datelist;
    }

    public static void getDate(String date) throws ParseException {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = sf.parse(date);
        System.out.println("现在的日期是：" + sf.format(parse));
        Calendar c = Calendar.getInstance();
        System.out.println("当前时间 "+c.getTime());
        c.setTime(parse);
        c.add(Calendar.DATE, 2);// num为增加的天数，可以改变的
        parse = c.getTime();
        String format = sf.format(parse);
        System.out.println("增加天数以后的日期：" + format);
        Date date1 = new Date();
        date1.setTime(parse.getTime()-8*60*60*1000);
        System.out.println("减少小时：" + sf.format(date1));

        System.out.println(date1.getTime() > parse.getTime());
    }


}
